package tt.lab.pmbok.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;


public class PmbokProcess implements Comparable<PmbokProcess>{

	private Set<ProcessTool> tools;
	private Set<ProcessInout> inouts;
	private int id;
	private String name;
	private String description;
	private String pmbokId;
//	private int areaId;
	private Area area;
	private int groupId;

	
	private List<ProcessInout> ins;//sorted
	private List<ProcessInout> outs;//sorted
	
	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void setTools(Set<ProcessTool> tools) {
		this.tools = tools;
	}

	public Set<ProcessTool> getTools() {
		return tools;
	}

	
	public void setGroupId(int groupId) {
		this.groupId = groupId;
	}

	public int getGroupId() {
		return groupId;
	}



	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public String getDisplayName(){
		return this.getPmbokId() +" "+this.getName();
	}
	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public List<ProcessTool> getSortedTools() {
		List<ProcessTool> list = new ArrayList<ProcessTool>();
		for (ProcessTool tool : getTools()) {
			list.add(tool);
		}
		Collections.sort(list);
		return list;
	}

	private void updateInouts() {
		ins = new ArrayList<ProcessInout>();
		outs = new ArrayList<ProcessInout>();
		for (ProcessInout tool : getInouts()) {
			if(tool.getType().equals("I"))
				ins.add(tool);
			else if (tool.getType().equals("O"))
				outs.add(tool);
		}
		Collections.sort(ins);
		Collections.sort(outs);
	}
	
	public void setInouts(Set<ProcessInout> inouts) {
		this.inouts = inouts;
		updateInouts();
	}

	public Set<ProcessInout> getInouts() {
		return inouts;
	}


	public List<ProcessInout> getIns() {
		return ins;
	}

	public List<ProcessInout> getOuts() {
		return outs;
	}

	public int compareTo(PmbokProcess o) {
		if(this.id>o.id) return 1;
		else if (this.id<o.id) return -1;
		else return 0;
	}

	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	public String getPmbokId() {
		return pmbokId;
	}

	public void setPmbokId(String pmbokId) {
		this.pmbokId = pmbokId;
	}

}
